package gtc.edu.ybt.demo.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import gtc.edu.ybt.demo.entity.Course;
import gtc.edu.ybt.demo.entity.Grade;
import gtc.edu.ybt.demo.entity.Student;
import gtc.edu.ybt.demo.entity.SysUser;
import gtc.edu.ybt.demo.entity.TbClass;
import gtc.edu.ybt.demo.repository.CourseRepository;
import gtc.edu.ybt.demo.repository.GradeRepository;
import gtc.edu.ybt.demo.security.UserUtils;
import gtc.edu.ybt.demo.service.CourseService;
import gtc.edu.ybt.demo.service.GradeService;
import gtc.edu.ybt.demo.service.StudentService;
import gtc.edu.ybt.demo.service.TbClassService;

@Controller
@RequestMapping(value = "/gradeMain")
public class GradeMainController {
	@Autowired
	private GradeService gradeService;
	@Autowired

	private StudentService studentService;
	
	private UserUtils userUtils;
	@Autowired
	private GradeRepository graderepositor;
	@Autowired
	private CourseRepository courseService;
	@Autowired
	private TbClassService tbClassService;

	@RequestMapping(value = "/classGrade")
	public String bj(ModelMap modelMap) {
	  List<TbClass> bjs=tbClassService.findAll();
		modelMap.put("bjs",bjs);
		return "gradeMain/classGrade";
	}
	@RequestMapping(value = "/cjb")
	public String biao(Integer bjId,ModelMap modelMap) {
		List<Course> courses=courseService.findAll();
	   List<Student> students=studentService.findByTbClassId(bjId);
	   
	   modelMap.put("cjb",students);
	   modelMap.put("kcs",courses);
	   System.out.println(bjId);
	   System.out.println(courses);
		return "gradeMain/cjb";
		
	}
	@RequestMapping(value = "/bjlr")
	public String kclrcjBj(ModelMap modelMap) {
		List<TbClass> bjs=tbClassService.findAll();
		List<Course> kcs=courseService.findAll();
		modelMap.put("kcs",kcs);
		modelMap.put("bjs",bjs);
		return "gradeMain/bjlr";
	}
	@RequestMapping(value = "/allStudentGrade")
	public String list(ModelMap modelMap) {
		List<TbClass> tbClass=tbClassService.findAll();
		modelMap.put("list",tbClass);
		return "gradeMain/allStudentGrade";
	}
	@RequestMapping(value = "bjChange")
	public String bjChange(Integer bjId, ModelMap modelMap) {
		List<Course> courses = gradeService.findCourseByTbClassId(bjId);
		List<List<Object>> cjb = gradeService.getCjb(bjId, courses);
		modelMap.put("kcs", courses);
		modelMap.put("cjb", cjb);
		return "gradeMain/cjb";

	}

}
	
